import { getBase } from "@/Api/productionmanage/ProductManage"
// 获取商家投入品信息 接口

const product = {
    namespaced: true,
    state: () => ({
        baseOptions: [], // 基地信息
        // 合格选择框的信息
        qualifiedOptions: [{
            value: '1',
            label: '合格'
        }, {
            value: '0',
            label: '不合格'
        }],
        // 类型选择框
        gradeOptions: [{
            value: '1',
            label: '一等品'
        }, {
            value: '2',
            label: '二等品'
        }, {
            value: '3',
            label: '三等品'
        }],
        // 是否上架信息
        onShelfOptions: [{
            value: '1',
            label: '上架'
        }, {
            value: '0',
            label: '下架'
        }],
        // 公共校验规则
        editFormRules: {
            skuNumber: [{
                required: true,
                message: '请输入'
            }],
            name: [{
                required: true,
                message: '请输入'
            }],
            species: [{
                required: true,
                message: '请输入'
            }],
            onShelf: [{
                required: true,
                message: '请选择'
            }],
            baseId: [{
                required: true,
                message: '请选择'
            }],
            principalName: [{
                required: true,
                message: '请输入'
            }],
            expirationDate: [{
                required: true,
                message: '请输入'
            }],
            bestTasteDay: [{
                required: true,
                message: '请输入'
            }],
            grade: [{
                required: true,
                message: '请选择'
            }],
            packageType: [{
                required: true,
                message: '请输入'
            }],
            unitPrice: [{
                required: true,
                message: '请输入'
            }],
            unit: [{
                required: true,
                message: '请输入'
            }],
        },
    }),
    getters: {
        // 获取库存信息
        baseOptions: (state) => state.baseOptions,
        // 获取校验规则 
        rules: (state) => state.editFormRules,
        // 获取合格选择框
        qualifiedOptions: (state) => state.qualifiedOptions,
        // 获取等级选择框
        gradeOptions: (state) => state.gradeOptions,
        // 获取上架选择框
        onShelfOptions: (state) => state.onShelfOptions,
    },
    mutations: {
        //  保存基地信息
        setBaseInfo(state, e) {
            state.baseOptions = e
            console.log(state.baseOptions)
        }
    },
    actions: {
        //在APP.vue首次调用获取 
        // context 包含store的state和mutations的方法
        //获取所有基地信息
        async getBaseInfo(context) {
            const { data: res } = await getBase();
            console.log(res)
            if (res.statusCode === 20000) {
                context.commit('setBaseInfo', res.data)
            }
        }
    }
}

export default product